package com.xx.springboot.test.RabbitMQ.publishSubScripe;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.xx.springboot.test.RabbitMQ.RabbitMQUtil;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * Created by xiaoxiunique on 2018-9-1.
 */
public class EmitLog {

    /**
     * 交易所名称
     */
    private static final String EXCHANGE_NAME = "logs";

    public static void main(String[] args) throws IOException, TimeoutException {
        Connection connection = RabbitMQUtil.getConnection();
        Channel channel = connection.createChannel();

        /**
         * 定义交易所, 选择 fanout 模式
         */
        channel.exchangeDeclare(EXCHANGE_NAME, "fanout");

        for (int i = 0 ; i < 1000 ; i++) {
            String message = "hello publish sub-scripe" + i;

            /**
             * 发送消息到 交易所
             */
            channel.basicPublish(EXCHANGE_NAME, "", null, message.getBytes());
            System.out.println(message + "send successful !");

        }

        //channel.close();
        //connection.close();
    }
}
